home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java for 3D & VRML Worlds
/
Java for 3d and VRML Worlds.iso
/
examples
/
chap04
/
AutomaticDoor.java
< prev
next >
Wrap
Text File
|
1996-09-20
|
1KB
|
45 lines
//
// toggle the light state.
// control the automatic door.
//
import vrml.*;
import vrml.node.*;
import vrml.field.*;
public class AutomaticDoor extends Script{
SFBool turnOnLight;
SFTime openDoor;
SFTime closeDoor;
// light state.
boolean onOff = false;
public void initialize(){
// get the reference of the event out 'turnOnLight'.
turnOnLight = (SFBool)getEventOut("turnOnLight");
// get the reference of the event out 'openDoor'.
openDoor = (SFTime)getEventOut("openDoor");
// get the reference of the event out 'closeDoor'.
closeDoor = (SFTime)getEventOut("closeDoor");
}
public void processEvent(Event e){
if(e.getName().equals("touched") == true){
// toggle the light state.
onOff = !onOff;
// send the event.
turnOnLight.setValue(onOff);
}else if(e.getName().equals("enterArea") == true){
if(true == onOff){
// open the door if the light is on.
openDoor.setValue(((ConstSFTime)e.getValue()).getValue());
}
}else if(e.getName().equals("exitArea") == true){
// close the door.
closeDoor.setValue(((ConstSFTime)e.getValue()).getValue());
}
}
}